/*
将一个罗马数转为整数
输入数在 1 至 3999 之间
I -- 1
V -- 5
X -- 10
L -- 50
C -- 100
D -- 500
M -- 1000
*/

/*
IV -- 4
VI -- 6

*/
(function(win) {
	function romanToInt(roman) {
		var isAddI = /IV|IX/g.test(roman);
		var isAddX = /XL|XC/g.test(roman);
		var isAddC = /CD|CM/g.test(roman);
		var num = 0;
		var romanArr = roman.split('');
		for (let i = 0; i < romanArr.length; i++) {
			switch (romanArr[i]) {
				case 'M':
					num += 1000;
					break;
				case 'D':
					num += 500;
					break;
				case 'C':
					num += 100;
					break;
				case 'L':
					num += 50;
					break;
				case 'X':
					num += 10;
					break;
				case 'V':
					num += 5;
					break;
				case 'I':
					num += 1;
					break;
			}
		}
		num -= isAddI ? 2 : 0;
		num -= isAddX ? 20 : 0;
		num -= isAddC ? 200 : 0;
		return num;
	}

	var test = romanToInt("MMCDXXV");
	console.log(test);
})(window)